//查询人员的

import 'package:flutter/cupertino.dart';
import 'package:p_location/common/res/common_res.dart';
import 'package:p_location/map/constant/map_http_url.dart';
import 'package:p_location/map/res/search_person_detail.dart';
import 'package:p_location/map/res/search_person_info.dart';
import 'package:p_location/map/res/search_person_res.dart';
import 'package:p_location/net/dio_http_client.dart';
import 'package:p_location/net/net_listener_impl.dart';
import 'package:dio/dio.dart';

class SearchPersonUtil {
  final String keyword;

  final String loadingTip;

  final Function infoSuccess;

  final Function infoFailure;

  SearchPersonUtil(
      this.keyword, this.infoSuccess, this.infoFailure,{this.loadingTip = ""});

  requestSearchPerson(BuildContext context) async {
    Map<String, dynamic> params = {};
    await DioHttpClient.requestPost(
        context,
        '${MapHttpUrl.PEOPLE_INFO_SEARCH_URL}?keyword=${this.keyword}',
        params,
        NetListenerImpl((Response response) {
          if (response != null && response.data != null) {
            List<SearchPersonDetail> _detailList = [];
            SearchPersonRes res = SearchPersonRes.fromJson(response.data);
            _detailList = [];
            if (res != null && res.data != null) {
              SearchPersonInfo searchPersonInfo = res.data;
              if (searchPersonInfo != null) {
                if (searchPersonInfo.employeeList != null) {
                  _detailList.addAll(searchPersonInfo.employeeList);
                }
                if (searchPersonInfo.guestList != null) {
                  _detailList.addAll(searchPersonInfo.guestList);
                }
                if (searchPersonInfo.workerList != null) {
                  _detailList.addAll(searchPersonInfo.workerList);
                }
                if (searchPersonInfo.innerCarList != null) {
                  _detailList.addAll(searchPersonInfo.innerCarList);
                }
                if (searchPersonInfo.outerCarList != null) {
                  _detailList.addAll(searchPersonInfo.outerCarList);
                }
                if (infoSuccess != null) {
                  infoSuccess(_detailList);
                }
              } else {
                if (infoFailure != null) {
                  infoFailure();
                }
              }
            }
          }
        }, (CommonRes errorRes) {
          if (infoFailure != null) {
            infoFailure();
          }
        }),loadingTip: loadingTip);
  }
}
